package com.shujia.flink.window

import java.lang

import com.alibaba.fastjson.{JSON, JSONObject}

object Demo6Json {
  def main(args: Array[String]): Unit = {

    val json = "{\"car\":\"皖A9A7N2\",\"city_code\":\"340500\",\"county_code\":\"340522\",\"card\":117988031603010,\"camera_id\":\"00012\",\"orientation\":\"西北\",\"road_id\":34053114,\"time\":1614714188,\"speed\":58.51}"

    /**
      * fastJson解析json字符串
      *
      */

    //将json字符串转换成json对象，sjon对象可以使用key获取value
    val jsonObj: JSONObject = JSON.parseObject(json)

    //直接通过key获取value
    val card: String = jsonObj.getString("card")
    val time: Long = jsonObj.getLong("time")
    val speed: lang.Double = jsonObj.getDouble("speed")
    println(card)
    println(time)
    println(speed)

  }

}
